# Contributor: Der Tiger <der.tiger.alpine@arcor.de>
# Maintainer: wener <wenermail@gmail.com>
pkgname=usbip-utils
pkgver=4.18.13
pkgrel=2
pkgdesc="Utilities for USB device sharing over IP network"
url="https://kernel.org/doc/readme/drivers-staging-usbip-userspace-README"
arch="all"
license="GPL-2.0"
depends="glib sysfsutils usbutils"
depends_dev="gcc automake autoconf eudev-dev libtool linux-headers sysfsutils-dev glib-dev"
makedepends="$depends_dev tar"
install=""
subpackages="$pkgname-dev $pkgname-doc"
source="https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-$pkgver.tar.gz
	usbip.initd
	usbip.confd
	fix-ppc64le-disable-werror.patch"

_baseurl="linux-$pkgver/tools/usb/usbip"
builddir="$srcdir/usbip"

unpack() {
	cd "$srcdir"

	mkdir "$builddir"
	tar -C $builddir --strip-components=4 -zxv -f $srcdir/linux-$pkgver.tar.gz $_baseurl
}

prepare() {
	local i
	cd "$builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i;;
		esac
	done
}

build() {
	cd "$builddir"
	export CFLAGS=$(echo $CFLAGS | sed 's|-Os|-O2|')
	export CPPFLAGS="$CFLAGS"
	/bin/sh autogen.sh
	./configure --prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--libdir=/usr/lib \
		--datarootdir=/usr/share
	make
}

check() {
	cd "$builddir"
	./src/usbip version
	./src/usbipd --version
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
	install -Dm755 "$srcdir"/usbip.initd "$pkgdir"/etc/init.d/usbip
	install -Dm644 "$srcdir"/usbip.confd "$pkgdir"/etc/conf.d/usbip
}

sha512sums="d8b6076617f1b6e88bb485165c0a36567bb6ab9c372ecabf749515f5b5c7de3a8c38a1a262d3b9f2feeda5a76a3fede493fe098811a01f06fe079fe5f7656ecb  linux-4.18.13.tar.gz
fcbd64d844c9bc187d08cef5995e91a46c0df78deb24e96ac9210c0e2c730eca0301970d9b8ffbf003df274682d05072431a26b59d8c491f396618268a12ec92  usbip.initd
eb8de617e27c4d5fdfee9c442e8f74b0afb4d0fe7b59eca3a19629eb70fea7e09b3c125bc968aa8810d845ce661c829bd0f3fdb2288664f2cccf423bc0ae6ae8  usbip.confd
473d194edc7677d0eb9864cf1e3922264ddd2d89e1015188f09c59e50a84a77f08d1e5c99700d4f3c8c01bea318aa614482f7902f0c97f5d87d6fbe388e840f8  fix-ppc64le-disable-werror.patch"
